// pages/signrecord/signrecord.js
const skinBehavior = require('../../../utils/themeSkin/skinBehavior');
var app = getApp();
Page({
  behaviors: [skinBehavior],
  /**
	 * 页面的初始数据
	 */
  data: {
    infoData: {},
    continue_days: '', //连续签到天数
    sign_total: '', //累计签到天数
    cumulative: '', //累计奖励
    sign_log: [], //签到记录
    sign_name: '', //签到名字
    integral: '',
    love_name:"",
    love_return:"",
    sign_model:{},
    love_return: "",//累计爱心返回值
    cumulative_point:'',//累计积分
    cumulative_coupon:'',//累计优惠劵
    cumulative_love:'',//累计爱心值
    is_love:false,//爱心值插件开关
    point:'',
    page:1,
    total_page:1,//总页面数
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    let integral = '';
    try {
      integral = wx.getStorageSync('integral');
    } catch (error) {
      console.log(error);
    }
    this.data.integral = integral;
    this.setData({integral});
    this.getData();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {

  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {

  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {

  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {

  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {
      
  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {
    this.onfresh()
  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {

  },
  getData() {
    let json ={
      page:this.data.page
    }
    let urlStr = app.getNetAddresss("plugin.sign.Frontend.Modules.Sign.Controllers.sign-log.log");
    var that = this;
    app._getNetWork({
      url: urlStr,
      data:json,
      success: function(res) {
        if(res.data.result !=1) return;
        let d = res.data.data;
        let ds =res.data
        let sign_log = res.data.data.sign_log.data;
        sign_log.forEach((item,key)=>{
          item.award_content = that.data.integral+item.award_content.substr(2);
        });
        that.setData({
          infoData: d,
          love_return:d.love_return,
          love_name:d.love_name,
          sign_model:d.sign_model,
          continue_days: d.continue_days,
          sign_total: d.sign_total,
          cumulative: that.data.integral+res.data.data.cumulative.substr(2),
          sign_log:that.data.sign_log.concat(sign_log),
          total_page:d.sign_log.total,
          sign_name: d.sign_name,
          is_love:d.is_love,
          cumulative_love : d.sign_model.cumulative_love,
          cumulative_coupon : d.sign_model.cumulative_coupon,
          cumulative_point : d.sign_model.cumulative_point,
          point:wx.getStorageSync('integral')
          // themeBaseColor:ds.basic_info.theme_color
        });
        wx.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: that.data.themeBaseColor,
          animation: {
            duration: 400,
            timingFunc: 'easeIn'
          }
        });
        wx.setNavigationBarTitle({
          title: that.data.sign_name ? (that.data.sign_name + '记录') : '记录'
        });
        if(that.data.page > d.sign_log.last_page){
          that.setData({
            page:d.sign_log.last_page
          })
          wx.showToast({
            title: '没有更多数据了',
            icon:'none'
          })
        }
      }
    });
  },
  onfresh(){
    wx.showLoading({
      title: 'loading',
    })
    console.log('下拉刷新');
    this.setData({
      page: this.data.page+1
    })
    this.getData()
    setTimeout(() =>{
      wx.hideLoading()
      // wx.stopReachBottom()
    },1000)
  }
});
